// datagrid commands

// RowEdit command
function DataGridRowEditCommand(grid, dataItem, rowIndex, oldValues, newValues) {
	this.init();
	this.grid = grid;
	this.rowIndex = rowIndex;
	this.dataItem = dataItem;
	this.oldValues = oldValues;
	this.newValues = newValues;
}
Object.extend( DataGridRowEditCommand.prototype, ReversibleCommand.prototype );
DataGridRowEditCommand.prototype.mainCommit = function() {
	for(var propName in this.newValues) {
		if(typeof this.newValues[propName] != "function") this.dataItem[propName] = this.newValues[propName];
	}
	this.grid.refreshRow(this.rowIndex);
	this.grid.refreshFooter();
}
DataGridRowEditCommand.prototype.mainRollback = function() {
	for(var propName in this.oldValues) {
		if(typeof this.oldValues[propName] != "function") this.dataItem[propName] = this.oldValues[propName];
	}
	this.grid.refreshRow(this.rowIndex);
	this.grid.refreshFooter();
}

// RowAdd command
function DataGridRowAddCommand(grid, dataItem, rowIndex) {
	this.init();
	this.grid = grid;
	this.dataItem = dataItem;
	this.rowIndex = rowIndex;
}
Object.extend( DataGridRowAddCommand.prototype, ReversibleCommand.prototype );
DataGridRowAddCommand.prototype.mainCommit = function() {
	if(this.rowIndex != undefined) {
		this.grid.insertRow(this.dataItem, this.rowIndex);
	} else {
		this.rowIndex = this.grid.appendRow(this.dataItem);
	}
}
DataGridRowAddCommand.prototype.mainRollback = function() {
	this.grid.removeRow(this.rowIndex);
}

// RowDelete command
function DataGridRowDeleteCommand(grid, rowIndex) {
	this.init();
	this.grid = grid;
	this.rowIndex = rowIndex;
	this.dataItem = grid.model[rowIndex];
}
Object.extend( DataGridRowDeleteCommand.prototype, ReversibleCommand.prototype );
DataGridRowDeleteCommand.prototype.mainCommit = function() {
	this.grid.removeRow(this.rowIndex);
}
DataGridRowDeleteCommand.prototype.mainRollback = function() {
	this.grid.insertRow(this.dataItem, this.rowIndex);
}



/*
 * Group: Changelog
 *
 * 04/10/2006:
 *	- DataGridRowEditCommand
 *	- DataGridRowAddCommand
 *	- DataGridRowDeleteCommand
 * 20/10/2006:
 *	- DataGridRowEditCommand refreshes footer
 */